﻿using AutoMapper;
using KuaFu.CardIssuing.OpenApi.Args.MerchantAccount;
using KuaFu.Core;
using KuaFu.Extensions;
using KuaFu.Extensions.Base;
using KuaFu.Shared;
using KuaFu.Shared.AccountService.Enums;
using KuaFu.Shared.AccountService.Services.Account;
using KuaFu.Shared.AccountService.Services.Transaction;
using KuaFu.Shared.CardIssuingPlatformService.Services.MerchantAccount;
using KuaFu.Shared.CommonService.DTOs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace KuaFu.CardIssuing.OpenApi.Controllers
{
    [Route("api/merchant_account")]
    public class MerchantAccountController : BaseApiController
    {
        private readonly IServiceProvider _serviceProvider;
        private readonly IMapper _mapper;
        private readonly UserInfo _userInfo;

        public MerchantAccountController(IServiceProvider serviceProvider, IMapper mapper, UserInfo userInfo)
        {
            _serviceProvider = serviceProvider;
            _mapper = mapper;
            _userInfo = userInfo;
        }

        /// <summary>
        /// 商户账户支付
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        [HttpPost("pay")]
        public async Task<ApiResult> PayAsync([FromBody] MerchantAccountPayArgs args)
        {

            var result = await _serviceProvider.GetRequiredService<MerchantAccountPaymentService>().ExecuteAsync(new MerchantAccountPaymentArgument(
                _userInfo.GetMerhcantId(),
                args.Currency,
                args.CardProductId,
                args.FeeType,
                args.OrderId,
                args.Amount,
                args.Remark));

            return new ApiResult(result);
        }
    }
}
